<template>

    <el-menu :default-active="$route.path" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
        background-color="#333744" text-color="#fff" active-text-color="#ffd04b" unique-opened router >
        <!-- 一级菜单 -->
        <el-submenu :index="menu.path" v-for="menu in menuList" :key="menu.id" >
            <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{menu.authName}}</span>
            </template>
            <el-menu-item :index="cMenu.path" v-for="cMenu in menu.children" :key="cMenu.id" >
                <i class="el-icon-menu"></i>
                <span slot="title">{{cMenu.authName}}</span>
            </el-menu-item>
        </el-submenu>
    </el-menu>

</template>

<script>
import { reqMenuList } from '@/api'

export default {
    created() {
        this.getMenuList()
    },
    data() {
        return {
            menuList: [],
            iconList: []
        }
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath)
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath)
        },
        async getMenuList() {
            const {
                data,
                meta: { msg, status }
            } = await reqMenuList()

            if (200 !== status) return this.$message.error(msg)
            this.menuList = data
        }
    }
}
</script>

<style lang="less" scoped>
.el-menu {
    border-right: 0px;
}
</style>